package com.fundboss.display;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.market.MarketConfig;

public class TimeParamPanel  extends JPanel{

	public TimeParamPanel(final MarketConfig config){
		setLayout(new GridLayout(0,2));
		JLabel title = new JLabel("Time");
		title.setFont(new Font("Arial",Font.BOLD,18));
		add(title);
		add(new JLabel(""));
		
		add(new JLabel("Iterations (total periods)"));
		final JComboBox iterations = new JComboBox(new Object[]{"80","100","150","200","250"});
		iterations.setSelectedItem("100");
		config.setIterations(100);
		add(iterations);
		iterations.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String option = (String) iterations.getSelectedItem();
				config.setIterations(Integer.parseInt(option));
			}
		});
		
		add(new JLabel("Statistics data sample"));
		final JComboBox dataSample = new JComboBox(new Object[]{"20","40","60","80","100","150","200"});
		dataSample.setSelectedItem("60");
		config.setTradeDelay(60);
		add(dataSample);
		dataSample.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String option = (String) dataSample.getSelectedItem();
				config.setTradeDelay(Integer.parseInt(option));
			}
		});
		
		add(new JLabel("Periods per year"));
		final JComboBox periodsPerYear = new JComboBox(new Object[]{"1","6","12","52","100"});
		periodsPerYear.setSelectedItem("12");
		config.setPeriodsInYear(12);
		add(periodsPerYear);
		periodsPerYear.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String option = ((String) periodsPerYear.getSelectedItem()).trim();
				config.setPeriodsInYear(Integer.parseInt(option));
			}
		});
		
		add(new JLabel("Periods Per Sample For Regression"));
		final JComboBox periodsPerSample = new JComboBox(new Object[]{"1","2","3"});
		periodsPerSample.setSelectedItem("1");
		config.setPeriodsPerSampleForRegression(1);
		add(periodsPerSample);
		periodsPerSample.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				String option = ((String) periodsPerSample.getSelectedItem()).trim();
				config.setPeriodsPerSampleForRegression(Integer.parseInt(option));
			}
		});
	}
}
